/*
页面参数
*/
var hyischoiced=[];//已经选择的行业
var xqischoiced=[];//已经选择的兴趣
var xqchoicenum=0;
var choicenum=0;
var pulu_redbag={};//资源 红包参数
var qtypenum =3;
var question = {};
    question.score =0;//分数
    question.qtype=3;//2问题3经验
    question.isstrangersee = 1;//陌生人是否可见  0否1是
    question.ishidename = 0;//是否匿名发布  0否1是
    question.iswhocansee = 0;//是否是部分可见 0否1是 和 isforbidwhosee互斥
    question.isforbidwhosee = 0;//是否是不给谁看  0否1是 和 iswhocansee互斥
    //类别筛选
    question.chikui= 0, //吃亏经验
    question.huasuan= 0, //划算
    question.xinqi= 0, //新奇
    question.qita= 0, //其他
    question.tuijiandy= 0, // 推荐电影
    question.tuijianfd= 0, //推荐饭店
    question.youwan= 0, //游玩
    question.yejy= 0, //育儿
    question.gzjy= 0, //工作
    question.jkjy= 0, //健康经验
    question.gwjy= 0, //购物
    question.shu= 0; //书
var chickednum=0; //选取个数
var atmeIsHideName=0;
var imgresult;
var imgs = [];//图片列表-------用于向服务器传递参数
var winscrolltop;
var imghash={};//保存服务器返回的图片地址 “images.localId[i]”：imgurl
var delimgid="";//要删除的图片的Id
var persons = [];  //招唤的人
var havesendexpnum=0;//发布三个普通经验才能发高额
    //问题转经验
var queTitle="";
var queContent="";
var keywordtitle="";//关键词生成的标题
    //是否超过10个经验
var sendlasTen=true;//默认没有发十个经验
var urlfrom=location.href;
    //输入框
var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var lacationhash={};//保存所有推荐定位的hash
var choicel=[];//已经选择的定位
var shengshi;//市
var pagenum=1;//选择城市页码
var tonum1=0; //右侧导航条 跳转位置
var pageindex=1; //城市返回
var nowlocation;//当前位置 定位
    //展开上层列表
var choicePuluPeople=false;
//var plist = [];//能看此图片的人的列表
var singleCallPerson=[];//单身资源召唤的好友
//var sendfriend=0;//判断当前朋友列表对应图片还是问题  对应问题
//var callfrienfname=[];
//var labeldata;//保存标签组
//var woseetype="";//用来判断当前标签组是部分可见 还是提醒谁看
//var isSingleCallSee=false;//单身资源提醒谁看
//var isSingleOnlySee=false;//单身资源只给谁看


/*
 页面初始化判断
 */
    //修复PC https http cookie
if(!is_weixn()&&(document.referrer)){ //不在微信端 且有来源地址 已拼接ID为准；
    if(/id=/.test(location.href)){
        var realId=(location.href).match(/id=[0-9a-z]+/)[0].split("=")[1];
        $.cookie("MYID",realId);
        id=realId;
    }
}
    //2问题3经验
if(qtypenum){question.qtype=qtypenum};


/*
 页面按钮控件
*/
var imgbtn=document.querySelector(".modifier.image");//主页面图片按钮
var choiceimgplace=document.getElementsByClassName("choiceimgplace")[0];
var imgokbtn=document.querySelector(".imgokbtn");//图片页面确定按钮
var imgallsee=document.getElementsByClassName("imgallsee");
var bodyplace=document.getElementsByClassName("bodyplace")[0];//主页面
var sendquesbtn=document.getElementsByClassName("sendquesbtn")[0];//提交问题按钮
var modalbg=document.getElementsByClassName("modal_bg")[0];
var modal=document.getElementsByClassName("action_menu_container2")[0];
//var imgchoicedFDokbtn=document.getElementById("imgchoicedFDokbtn");//图片好友列表确定按钮
//var imgchoicefriend=document.getElementById("sd-imgchoicefriend");//图片选择好友区域
//var strangecansee=document.getElementById("strangecansee");//陌生人不可见
//var hidename=document.getElementById("hidename");//陌生人不可见
//var somecansee=document.getElementById("somecansee");//问题经验部分可见
//var inputbox1=document.querySelector("#inputbox1 div");//主页面确定按钮
//var inputbox3=document.querySelector("#hyabtnok");//行业页面确定按钮
//var tishiwords=document.getElementById("tishiwords");
//var cancel=document.getElementsByClassName("cancel");
//问题相关按钮控件
//var callfriend=$("#callfriend")[0];//提醒谁看


/*
 页面初始化样式
 */
$("#locationbox2").css("display","none");//问题定位默认关闭
$("#radioexp").prop("checked",true);
$(".queskind").html("经验");
$("#sendinfop").html("正在上传经验，请耐心等待..");
document.querySelector(".page_title.unified").innerHTML="分享经验";
$("#keywordinput").attr("placeholder","必填，且在文中出现过");
$("#contentword").attr("placeholder","最近的电影推荐，饭店推荐，游玩的地方，好看的书...\n上班交通经验，推荐的工作午餐...\n吃亏经历，新奇事,划算事...");


/*
 页面初始获取数据
 */
    //发布三个普通经验才能发高额
$.ajax({
    type:"get",
    url:"https://www.pulu.com/webapi/api/puluquestion/GetExpCountByUserId?userId="+id,
    datatype:"json",
    success:function(data){
        havesendexpnum=data.Data;
    }
});

    //动态生成nav列表
$.ajax({
    type:"get",
    url:"https://www.pulu.com/webapi/api/Pulu_fltype/Getpulu_fltype",
    datatype:"json",
    success:function(d){
        $.each(d.Data,function(n,j){
            switch(j.id){
                case 1: $("#chikui").next().html(j.name);break;//吃亏
                case 2: $("#huasuan").next().html(j.name);break;//划算
                case 3: $("#xinqi").next().html(j.name);break;//新奇
                case 4: $("#qita").next().html(j.name);break;//其他
                case 5: $("#tuijiandy").next().html(j.name);break;//电影
                case 6: $("#tuijianfd").next().html(j.name);break;//饭店
                case 7: $("#youwan").next().html(j.name);break;//游玩
                case 8: $("#shu").next().html(j.name);break;//书
                case 22: $("#nearlyexp").next().html(j.name);break;//附近
                case 23: $("#rensheng").next().html(j.name);break;//人生
                case 24: $("#yejy").next().html(j.name);break;//育儿
                case 25: $("#gzjy").next().html(j.name);break;//工作
                case 26: $("#jkjy").next().html(j.name);break;//健康
                case 27: $("#gwjy").next().html(j.name);break;//购物
            }
        });
    }
});

    //发布问题获取账户余额
$.ajax({
    type:"get",
    url:lastscoreurl+id,
    success:function(d){
        userallmoney=parseInt(d.Data)/100;
    }
});

    //有没有传入经验ID 召唤用户，关键词数据$.cookie("expkeyword")中保存经验id
if($.cookie("expkeyword")||/keyword=/.test(location.href)){
    $("#samekeyword").css("display","block");
    var eid;
    if(/keyword=/.test(location.href)){eid=(location.href).match(/keyword=[0-9]+/)[0].match(/[0-9]+/)[0];}
    if($.cookie("expkeyword")){eid=$.cookie("expkeyword")};
    $.cookie("sendque")=="question"?$("#samekeyword").css("display","none"):$("#samekeyword").css("display","block");
    var sendexptype=3;                     //网址参数 微信菜单栏进入  防止cookie影响tohref.js换进入的参数
    if(($.cookie("sendque")=="question")||/sendque=question/.test(location.href)){
        sendexptype=2;
    }
    $.ajax({
        type:"get",
        datatype:"json",
        url:hexpnoteurl+eid+"&qtype="+sendexptype,
        success:function(d){
            $("#keywordinput").val(d.Data.keywords);
            if(d.Data.payuserids){
                $.each(d.Data.payuserids,function(i,e){
                    if(e!=id){
                        persons.push(e);
                    }
                });
            }
        }
    })
}

    //问题转经验
if(/queChange=/.test(location.href)){
    $.cookie("sendque","");
    $("#choiceque").css("display","none");
    $("#choiceexp label").html("经验转换");
    $(".priceinputbox.new.norexpinput").remove();
    var qid=(location.href).match(/queChange=[0-9]+/)[0].match(/[0-9]+/)[0];
    $(".changetype input[type='radio']").css("display","none");
    $.ajax({
        type:"get",
        url:trangetqueurl+qid,
        datatype: "json",
        success:function(data){
            //内容
            $("#contentword").val(data.Data.title+data.Data.content);
            queTitle=data.Data.title;
            queContent=data.Data.content;
            //关键词
            $("#keywordinput").val(data.Data.keywords);
            //图片
            if(data.Data.imgs&&data.Data.imgs.length>0){
                for(var i=0;i<data.Data.imgs.length;i++){
                    imghash[data.Data.imgs[i]]=data.Data.imgs[i];
                    $("<div class='mainshowimgbox' style='height:21vw;width:21vw;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+data.Data.imgs[i]+"' data-img='"+data.Data.imgs[i]+"'><i class='choiced' onclick='chooseimg(this)' data-img='"+data.Data.imgs[i]+"'></i><img src='"+imgurl+data.Data.imgs[i]+"'></div>").insertBefore("#questionbody .modifier.image");
                }
            }
        }
    });
}

    //能否发经验
if($.cookie("MYID")){
    $.ajax({
        type:"get",
        url:"https://www.pulu.com/webapi/api/puluquestion/CanAddExp?userId="+$.cookie("MYID"),
        datatype:"json",
        success:function(d){
            sendlasTen= d.Data;
        }
    });
}

    //加载关注列表
$.ajax({
    datatype:"json",
    type:"get",
    url:getPuluTopLayer+"?userId="+id,
    success:function(d){
        if(d.Data&&d.Data.length>0){
            for(var i=0;i< d.Data.length;i++){
                var moneyNum= 0,showNum=0;
                if(d.Data[i].seeFee){
                    moneyNum=parseFloat(d.Data[i].seeFee);
                    showNum=parseFloat(d.Data[i].seeFee)/100;
                    $("#puluPeople .topPeopleList").append('<div class="puluPeopleList"><input type="checkbox" id="'+d.Data[i].userId+'" value="'+moneyNum+'"><label for="'+d.Data[i].userId+'">指定给'+d.Data[i].userName+'看  需花'+showNum+'元</label></div>')
                }
            }
            ////排序
            //friendarr= (d.Data).sort(compare);
            //hasharr={};//判断字母是否存在
            //for(var i=0;i<friendarr.length;i++){
            //    if(friendarr[i].userName){
            //        friendarr[this.index]=i;
            //        //如果昵称开头为汉字或英文字母
            //        var key=Pinyin.getCamelChars(friendarr[i].userName[0]);
            //        var headimg="<img src='img/af8.png' class='topic_photo_img'/>"
            //        if(friendarr[i].headimg){
            //            headimg="<img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/>";
            //        }
            //        if(key.match(/[a-z|A-Z]/)){
            //            key=key.toLowerCase();
            //
            //            if(!hasharr[Pinyin.getCamelChars(friendarr[i].userName[0])]){
            //                hasharr[Pinyin.getCamelChars(friendarr[i].userName[0])]=i;
            //            }
            //            var realname="";
            //            if(friendarr[i].realName){realname=" ("+friendarr[i].realName+")";}
            //            $("#maina").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].userId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].userId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].userName+realname+"</div> </div>");
            //            $("#aa").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].userId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].userId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].userId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].userName+realname+"</div> </div>");
            //        }else{
            //            $("#mainjinghao").css("display","block");
            //            var realname="";
            //            if(friendarr[i].realName){realname=" ("+friendarr[i].realName+")";}
            //            $("#mainjinghao").append("<div class='friends' id='"+friendarr[i].userId+"'> <input type='checkbox' class='addchatpeoplebtn'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].userId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].userName+realname+"</div> </div>");
            //            $("#jinghao").css("display","block");
            //            $("#jinghao").append("<div class='friends' id='"+friendarr[i].userId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].userId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].userId+"'>"+headimg+"</a> </div> <div class='innerplace tc_text'>"+friendarr[i].userName+realname+"</div> </div>");
            //        };
            //    }
            //}
            //for(var key in hasharr){
            //    key=key.toLowerCase();
            //    $("#sd-imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
            //    $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");
            //    $("#imgchoicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
            //    $("#somesee .section_header.section_header_gray."+key).eq(0).css("display","block");
            //};
        }
    }
});

    //发问题
if($.cookie("sendque")=="question"||/sendque=question/.test(location.href)){
    showQueStyle();
    question.qtype=2;
    document.querySelector(".page_title.unified").innerHTML="悬赏";
    $("#contentword").attr("placeholder","有什么烦恼解不开？\n有什么困惑想不通？\n有什么好奇的事？");
    $("#gaojilistbox .sendquestionpage:first-child").css("display","none");
}

    //单身资源......
//if(/goSingle/.test(location.href)||/goFilm/.test(location.href)||/goWork/.test(location.href)||/goHouse/.test(location.href)||/goProgect/.test(location.href)||/goRes/.test(location.href)||/goOther/.test(location.href)){
//    showQueStyle();
//    document.querySelector(".page_title.unified").innerHTML="发布资源";
//    $("#choiceexp").css("display","none");
//    $("#choiceque").css("display","none");
//    $(".changetype .title").css("display","block");
//    //$("div[id^='new4money']").css("display","block");
//    $("#new4money").css("display","block");
//    $("#new4money1").css("display","block");//免费 提醒文字
//    $("#locationbox2").css("display","none");
//    $("#gaojilistbox>.sendquestionpage:first-child").css("display","none");//相关网址
//    $(".sendquesbtn").html("完成");
//    if(/goSingle/.test(location.href)){
//        $("#callfriend2").css("display","block");//单身资源 提醒谁看 只给谁看
//        question.qtype=4;
//        $("#keyword>div.lf:first-child").html("人物标签");
//        $(".changetype .title").html("单身资源");
//        $("#location2>div:nth-child(2)").html("TA的位置");
//        $("#locationbox2").css("display","block");
//        $("#contentword").attr("placeholder","例如XX，IT程序员，今年27，有房有车，性格开朗，心地善良，工作努力，平时喜欢运动，读书等，看得上的不要错过哦！");
//        $("#keywordinput").attr("placeholder","个性，颜值，高富帅，白富美...");
//    }
//    else if(/goFilm/.test(location.href)){
//        question.qtype=5;
//        $("#keyword>div.lf:first-child").html("电影印象");
//        $(".changetype .title").html("电影评论");
//        $("#contentword").attr("placeholder","例如《杀破狼•贪狼》故事扎实，对古仔这条线的处理很丰满，绝望中还有移情。吴樾表现很好，有情有义的感觉到位。洪金宝的动作设计很为古仔藏拙，近身关节技，断手断脚，狠辣阴毒，没有套招，弱化设计感，推荐观看。");
//        $("#keywordinput").attr("placeholder","打斗炫，剧情好，特效棒...");
//    }
//    else if(/goWork/.test(location.href)){
//        question.qtype=6;
//        //$("#keyword>div.lf:first-child").html("人物标签");
//        $("#locationbox2").css("display","block");
//        $(".changetype .title").html("工作介绍");
//        $("#contentword").attr("placeholder","例如有朋友在南京的公司想招个项目经理，负责公司web和APP产品的项目管理工作，主导项目需求分析、开发管理工作等，有意的可以联系我");
//        $("#keywordinput").attr("placeholder","项目经理，APP，互联网...");
//    }
//    else if(/goHouse/.test(location.href)){
//        question.qtype=7;
//        $("#keyword>div.lf:first-child").html("房屋优点");
//        $("#locationbox2").css("display","block");
//        $(".changetype .title").html("租房买房");
//        $("#contentword").attr("placeholder","例如南京夫子庙附近，水游城西一新村精装好房，交通方便，2800 元/月，整租，小区物业非常好，环境很优美。生活便利：小区内有商铺，合理分布便利店，购买生活用品及买菜十分方便。");
//        $("#keywordinput").attr("placeholder","环境好，交通方便，租金便宜...");
//    }
//    else if(/goProgect/.test(location.href)){
//        question.qtype=8;
//        $("#keyword>div.lf:first-child").html("项目标签");
//        $("#locationbox2").css("display","block");
//        $(".changetype .title").html("项目资源");
//        $("#contentword").attr("placeholder","例如最近开发了一款APP，可以用来发经验，发悬赏，还可以分享各种资源、看资讯，感兴趣的小伙伴不妨下载试一下");
//        $("#keywordinput").attr("placeholder","APP，好玩，资讯，打发时间");
//    }
//    else if(/goRes/.test(location.href)){
//        question.qtype=9;
//        //$("#keyword>div.lf:first-child").html("");
//        $("#locationbox2").css("display","block");
//        $(".changetype .title").html("人脉资源");
//        $("#contentword").attr("placeholder","例如有朋友在腾讯中高层工作，对鹅场氛围环境想了解，或者想要求职应聘到腾讯，甚至交流合作等，这边可以联系搭桥。");
//        $("#keywordinput").attr("placeholder","腾讯，氛围，合作...");
//    }
//    else if(/goOther/.test(location.href)){
//        question.qtype=10;
//        //$("#keyword>div.lf:first-child").html("人物标签");
//        $("#locationbox2").css("display","block");
//        $(".changetype .title").html("其他资源");
//        $("#contentword").attr("placeholder","例如我知道个地方是旅游的好去处，虽然可能偏僻点，但风景环境不错，而且周边的饭菜质量也很好，大家想要去的旅游的话，可以试试哦");
//        $("#keywordinput").attr("placeholder","旅游，风景，环境");
//    }
//}
//else{
    $("#choiceexp").css("display","inline-block");
    if(!/queChange/.test(location.href)){$("#choiceque").css("display","inline-block");}
//}
////资源修改发布金额类型
//$("#new4moneyinput").bind("input","change",function(){
//    $("#new4moneyFree").prop("checked",false);
//    $("#new4redPay").prop("checked",false);
//    $("#new4moneyPay").prop("checked",true);
//    if($("#new4moneyinput").val().match(!/^[1-9]$|^[1-9][0-9]{1,2}$|^[1-9][0-9]{1,2}\.[0-9]{1}$|^[1-9]{1,3}\.[0-9]{1}$|^0\.[1-9]$/)){
//        if(parseFloat($("#new4moneyinput").val())>=1000){$("#new4moneyinput").val(999.9);}
//        if(/^0[0-9]+/.test($("#new4moneyinput").val())){$("#new4moneyinput").val($("#new4moneyinput").val().replace(/^0/,""));}
//        if(/\./.test($("#new4moneyinput").val())){
//            $("#new4moneyinput").val($("#new4moneyinput").val().match(/[0-9]{1,4}\.[0-9]{1}/)[0]);
//            if($("#new4moneyinput").val()=="0.0"){$("#new4moneyinput").val(0);}
//        }
//        if(/^00/.test($("#new4moneyinput").val())){$("#new4moneyinput").val(0);}
//    }
//});

if(/expType/.test(location.href)){
    var et=(location.href).match(/expType=[a-z]+/)[0].split("=")[1];
    $("#"+et).attr("checked",true);
    switch(et) {
        case "chikui":question.chikui=1;break;
        case "huasuan":question.huasuan=1;break;
        case "xinqi":question.xinqi=1;break;
        case "qita":question.qita=1;break;
        case "tuijiandy":question.tuijiandy=1;break;
        case "tuijianfd":question.tuijianfd=1;break;
        case "youwan":question.youwan=1;break;
        case "shu":question.shu=1;break;
        case "nearlyexp":question.youwan=1;break;//附近
        case "rensheng":question.shu=1;break;
        case "yejy":question.yejy=1;break;
        case "gzjy":question.gzjy=1;break;
        case "gwjy":question.gwjy=1;break;
        case "jkjy":question.jkjy=1;break;
    }
    chickednum=1;
}
else if($.cookie("expType")){console.log("执行");
    var et=$.cookie("expType");
    $("#"+et).attr("checked",true);
    switch(et) {
        case "chikui":question.chikui=1;break;
        case "huasuan":question.huasuan=1;break;
        case "xinqi":question.xinqi=1;break;
        case "qita":question.qita=1;break;
        case "tuijiandy":question.tuijiandy=1;break;
        case "tuijianfd":question.tuijianfd=1;break;
        case "youwan":question.youwan=1;break;
        case "shu":question.shu=1;break;
        case "nearlyexp":question.youwan=1;break;//附近
        case "rensheng":question.shu=1;break;
    }
    chickednum=1;
}


/*
 点击
 */
    //切换类型
$("#choiceque").click(function(){
    $("#highGradeLevel").css("display","block");
    if(!/queChange/.test(location.href)){ //不是问题赚经验
        $(".changetype>div#choiceexp").attr("class","");
        $(".changetype>div#choiceque").attr("class","active");
        question.qtype=2;
        $("#radioque").prop("checked",true);
        $("#radioexp").prop("checked",false);
        $("#samekeyword").css("display","none");
        $("#locationbox2").css("display","block");
        $("#highGradeLevel").css("display","block");
        $("#gaojilistbox .sendquestionpage:first-child").css("display","none");
        $("#sendtype").css("display","none");
        $("#contentword").attr("placeholder","有什么烦恼解不开？\n有什么困惑想不通？\n有什么好奇的事？");
    }
});

$("#choiceexp").click(function(){
    $(".changetype>div#choiceexp").attr("class","active");
    $(".changetype>div#choiceque").attr("class","");
    question.qtype=3;
    $("#radioque").prop("checked",false);
    $("#radioexp").prop("checked",true);
    $("#locationbox2").css("display","none");
    $("#gaojilistbox .sendquestionpage:first-child").css("display","block");
    $("#sendtype").css("display","block");
    $("#contentword").attr("placeholder","最近的电影推荐，饭店推荐，游玩的地方，好看的书...\n上班交通经验，推荐的工作午餐...\n吃亏经历，新奇事,划算事...");
    if($("#hexpinput").prop("checked")&&havesendexpnum<3){
        $("#highGradeLevel").css("display","none");
    }
});
    //删除大图
$("#delthisimgbtn").click(function(e){
    imghash[delimgid]="";//清除对应ID 保存的服务器图片地址
    //页面中删掉图片
    var imgbox=document.getElementsByClassName("mainshowimgbox");
    for(var i= 0,r=imgbox.length;i<r;i++){
        if(imgbox[i].dataset.img==delimgid){
            $(".mainshowimgbox")[i].remove();
            $(imgbtn).css("display","block");
        }
    }
    $(".modifier.image").css("display","inlineBlock");
    $("#page_wrapper").css("display","block");
    $("#digimgplace").css("display","none");
    $("#showimg").attr("src","");
});
    //关闭地图区域
$("#digimgplace").click(function(e){
    if(e.id!="delthisimgbtn"){
        $("#page_wrapper").css("display","block");
        $("#digimgplace").css("display","none");
        if(winscrolltop>0){
            $(window).scrollTop(winscrolltop);
        }
    }
});
    //金额设置返回
$("#pricepagebackbtn").click(function(){
    $("#pricepage").css("display","none");
    $("#outbox1").css("display","block");
});
    //点击后退
$("#maingobackbtn").click(function(){
    var conf=confirm("您的数据不会被保存，确定退出吗");
    if(conf===true){
        if(document.referrer&&!/sendexpgpc/.test(document.referrer)&&!/code=/.test(document.referrer)){
            history.go(-1);
        }
        else{location.href="pulu.html";}
    }
});
    //谁可以看页面返回
$("#whocanseebtn").click(function(){
    bodyplace.style.display="block";
});
    //切换高级选项
$("#highGradeLevel>.clickTitle").click(function(){
    $("#puluPeople").toggle();
});
    //下一步按钮//弹框 确定发经验 发悬赏
sendquesbtn.onclick=function(){
    if(/goSingle/.test(location.href)){
        question.qtype=4;
    }else if(/goFilm/.test(location.href)){
        question.qtype=5;
    }else if(/goWork/.test(location.href)){
        question.qtype=6;
    }else if(/goHouse/.test(location.href)){
        question.qtype=7;
    }else if(/goProgect/.test(location.href)){ //项目
        question.qtype=8;
    }else if(/goRes/.test(location.href)){ //人脉
        question.qtype=9;
    }else if(/goOther/.test(location.href)){ //其他
        question.qtype=10;
    }
    else{
        if($("#choiceque").attr("class")=="active"){
            question.qtype=2;
        }else if($("#choiceexp").attr("class")=="active"){
            question.qtype=3;
        }
    }
    $("div.exp").css("display","block");
    $("div.que").css("display","none");
    //console.log("关闭");

    if($("#contentword").val().trim().length<10&&(question.qtype)!=2){
        alert("字数有点少，再加点吧，至少10字哦");
    }else if(document.getElementById("keywordinput").value&&!document.getElementById("keywordinput").value.match(/^\s+$/g)){
        if(question.qtype==3){
            //经验要选择类别
            if(!$(".td input:checked")[0]){alert("请选择经验类别");return;}
            if(sendlasTen){
                var outbox1=document.getElementById("outbox1");
                $("#pricepage").css("display","block");
                $("#outbox1").css("display","none");
                keywordtitle=document.getElementById("keywordinput").value;
                $(window).scrollTop(0);
            }
            else{
                alert("您每日分享经验10次机会已用完");
            }
        }
        else if(question.qtype==2){
            //$(".paynoteplace").css("display","block");
            //$("body").attr("class","overflow");
            //$("#gaojilistbox").css("display","none");
            //$("#gaojiimg").attr("src","img/darr01.png");
            //$("#price").val("");
            //changeBodyHeight();
            $("div.exp").css("display","none");
            $("div.que").css("display","block");
            $("#pricepage").css("display","block");
            $("#outbox1").css("display","none");
        }
        //else{ //单身资源...
        //    //判断是否免费
        //    if($("#new4moneyFree").prop("checked")){
        //        getExpData();
        //    }
        //    //付费查看
        //    else if($("#new4moneyPay").prop("checked")){
        //        if($("#new4moneyinput").val().match(/^[1-9]$|^[1-9][0-9]{1,3}$|^[1-9][0-9]{1,3}\.[0-9]{1}$|^[1-9]{1,4}\.[0-9]{1}$|^0\.[1-9]$/)){
        //            getExpData();
        //        }
        //        else{
        //            alert("金额最少0.1元");
        //        }
        //    }
        //    //发红包
        //    else{
        //        if(!/^[0-9]+$/.test($("#new4redNum").val())){
        //            alert("红包最少1个");
        //        }else if(!/^[1-9]$|^[1-9][0-9]{1,3}$|^[1-9][0-9]{1,3}\.[0-9]{1}$|^[1-9]{1,4}\.[0-9]{1}$|^0\.[1-9]$/.test($("#new4redinput").val())){
        //            alert("");
        //        }else{ //账户判断
        //            var redNum=parseInt($("#new4redNum").val());
        //            var redPay=parseFloat($("#new4redinput").val());
        //            var allRed=redNum*redPay;
        //            if(allRed>userallmoney){
        //                alert("您的账户余额不足");
        //            }
        //            else{
        //                pulu_redbag.qtype=question.qtype;
        //                pulu_redbag.count=redNum;
        //                pulu_redbag.score=redPay*100;
        //                getExpData();
        //            }
        //        }
        //    }
        //}
    }
    else{
        if(question.qtype==4){alert("人物标签不能为空");}
        else if(question.qtype==5){alert("电影印象不能为空");}
        else if(question.qtype==6){alert("关键词不能为空");}
        else if(question.qtype==7){alert("房屋优点不能为空");}
        else{alert("关键词不能为空");}
    }
};
    //详细规则区域
$("#modaltishiwords").click(function(){
    $("#detailrule").css("display","block");
    $(".paynoteplace").css("display","none");
    $("body").attr("class","");
    $("body").css("height","auto");
});

$("#iknow").click(function(){
    $("#detailrule").css("display","none");
    //$(".paynoteplace").css("display","block");
    //$("body").attr("class","overflow");
    //$("#gaojilistbox").css("display","none");
    //$("#gaojiimg").attr("src","img/darr01.png");
    //changeBodyHeight();
});
    //选择“不显示城市”
$("#nolocation").click(function(){
    $("#location div:nth-child(2)").html("所在位置");
    if(/goSingle/.test(location.href)){
        $("#location2 div:nth-child(2)").html("TA的位置");
    }else{
        $("#location2 div:nth-child(2)").html("所在位置");
    }
    question.longitude="";
    question.latitude="";
    $(".myctywords").css("display","none");
    $(".myctywords").html("");
    $("#firstchoice").css("display","none");
    $("#outbox1").css("display","block");
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","block");
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","none");
});
    //选择省份
$("#shiname").click(function(e){
    $("#location div:nth-child(2)").html(shengshi);
    $("#location2 div:nth-child(2)").html(shengshi);
    $("#firstchoice").css("display","none");
    $(".myctywords").html(shengshi);
    $(".myctywords").css("display","none");
    choicel=null;
    $("#showmap").css("display","none");//页面
    $("#nolocation img").css("display","none");//钩
    $("#firstchoice img").css("display","none");
    $("#shiname img").css("display","block");
    $("#outbox1").css("display","block");
});
    //选地址返回
$("#mapgoback").click(function(){
    $("#showmap").css("display","none");//页面
    $("#outbox1").css("display","block");
});
    //取消搜索城市
$("#nosearch").click(function(){
    $("#searclocation div").remove();
    $("#nosearch").css("display","none");
    $("#locationlistplace").css("display","block");
    $("#otherlist").css("display","block");
    $("#searclocation").css("display","none");
});
    //经验定位展开
$("#location").click(function(){
    $("#locationlistplace").css("display","block");//搜索影响
    $("#otherlist").css("display","block");
    $("#showmap").css("display","block");//展开页面
    $("#outbox1").css("display","none");
});
    //问题定位展开
$("#location2").click(function(){
    $("#locationlistplace").css("display","block");//搜索影响
    $("#otherlist").css("display","block");
    $("#showmap").css("display","block");//展开页面
    $("#outbox1").css("display","none");
});
    //切换经验类型
$("#norexpinput").click(function(){
    $(".heiexpinput").css("display","none");
    $(".norexpinput").css("display","block");
    $("#errorword").css("display","none");
    $("#cannotsend").css("display","none");
    $("#oksenditbtn").css("display","block");
    $("#highGradeLevel").css("display","block");
    $("#norexpword").css("display","block");
    if($("#norexpinput").prop("checked")){console.log("norexpinput checked")}
});
$("#hexpinput").click(function(){
    if(havesendexpnum>2){
        $(".heiexpinput").css("display","block");
        $(".norexpinput").css("display","none");
        $("#errorword").css("display","block");
        $("#norexpword").css("display","none");
        if($("#hexpinput").prop("checked")){console.log("hexpinput checked")}
    }
    else{
        $(".norexpinput").css("display","none");
        $("#norexpword").css("display","none");
        $("#oksenditbtn").css("display","none");
        $("#highGradeLevel").css("display","none");
        $("#cannotsend").css("display","block");
    }
});
    //问题取消发布
$("#donotsendbtn").click(function(){
    $(".paynoteplace").css("display","none");
    $("body").attr("class","");
    $("body").css("height","auto");
});
    //发经验  悬赏
$("#oksenditbtn").click(function(){
    getExpData();
});
    //取消发布
$("#donotsendbtn").click(function(){
    $(".modal_bg.modal_bg2").css("display","none");
    $(".action_menu_container2").css("display","none");
});
    //搜索城市
$("#locationsearchbtn").click(function(){
    //城市搜索
    $("#searclocation div").remove();
    searchcity(pagenum);
});


/*
 方法
 */
    //问题页面的样式
function showQueStyle(){
    $("#radioque").prop("checked",true);
    $("#radioexp").prop("checked",false);
    $("#samekeyword").css("display","none");
    $("#locationbox2").css("display","block");
    $("#choiceque").attr("class","active");
    $("#choiceexp").attr("class","");
    $("#sendtype").css("display","none");
}
    //展示大图
function showbigimg(e){
    winscrolltop=$(window).scrollTop();
    $("#page_wrapper").css("display","none");
    $("#showimg").attr("src",e.firstChild.src); //大图片的地址 和 Id 相同
    $("#digimgplace").css("display","block");
    delimgid=e.dataset.img; //地址 和 Id 相同
}
    //输入框大小
function ResizeTextarea(a,row){
    if(!a){return}
    if(!row)
        row=5;
    var b=a.value.split("\n");
    var c=is_ie?1:0;
    c+=b.length;
    var d=a.cols;
    if(d<=20){d=40}
    for(var e=0;e<b.length;e++){
        if(b[e].length>=d){
            c+=Math.ceil(b[e].length/d)
        }
    }
    c=Math.max(c,row);
    if(c!=a.rows){
        a.rows=c;
    }
}
    //改变背景
function changeclass(){
    modalbg.className='modal_bg';
    modal.className='action_menu_container';
    clearTimeout();
    changedisplay();
}
    //改变背景
function changedisplay(){
    modalbg.style.display="none";
    modal.style.display="none";
}
    //展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
    //选择推荐城市
function getlocationhash(e){
    var name=lacationhash[e.id].name;
    $("#location div:nth-child(2)").html(lacationhash[e.id].name);
    $("#location2 div:nth-child(2)").html(lacationhash[e.id].name);
    $("#firstchoice .name").html(name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#firstchoice img").css("display","block");
    $("#firstchoice").css("display","block");
    $(".myctywords").html(lacationhash[e.id].name);
    $(".myctywords").css("display","none");
    $("#firstchoice").css("display","block");
    $("#firstchoice .name").html(lacationhash[e.id].name);
    $("#firstchoice .dizhi").html(lacationhash[e.id].address);
    $("#showmap").css("display","none");//页面
    $("#outbox1").css("display","block");
    $("#firstchoice img").css("display","block");
    $("#nolocation img").css("display","none");//钩
    $("#shiname img").css("display","none");
    //添加地址
    if(e.dataset.lng){
        question.longitude= e.dataset.lng;
        question.latitude=e.dataset.lat;
    }
}
    //搜索城市
function searchcity(pagenum){
    if($("#locationsearch input")[0].value){
        var searchword=$("#locationsearch input")[0].value;
        $("#nosearch").css("display","block");
        var map = new AMap.Map("mapplace", {
            resizeEnable: true
        });
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 20,
                pageIndex: pagenum,
                city: shengshi, //城市
                map: map
            });
            //关键字查询
            placeSearch.search(searchword,function(status, result){
                var data=result.poiList.pois;
                $(data).each(function(){
                    $("#searclocation").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                    if(!lacationhash[$(this)[0].id]){
                        lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                    }
                });
                $("#locationlistplace").css("display","none");
                $("#otherlist").css("display","none");
                $("#searclocation").css("display","block");
            });
        });
    }
}
    //展开上册列表
function showTopPeopleList(e){
    if(e.checked){
        $(".topPeopleList").css("display","block");
        choicePuluPeople=true;
    }else{
        $(".topPeopleList").css("display","none");
        choicePuluPeople=false;
    }
}
    //定位 城市//周边推荐
function otherlocal(position,shiname,pageindex){
    var map = new AMap.Map("mapplace", {
        resizeEnable: true
    });
    AMap.service(["AMap.PlaceSearch"], function() {
        var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
            pageSize: 20,

            pageIndex:pageindex,
            city: shiname, //城市
            map: map
            //panel: "otherlist"
        });
        var cpoint = position; //中心点坐标
        placeSearch.searchNearBy('', cpoint, 500, function(status, result) {
            var data=result.poiList.pois;
            $(data).each(function(){
                $("#otherlist").append("<div id="+$(this)[0].id+" onclick='getlocationhash(this)' data-lat='"+$(this)[0].location.lat+"' data-lng='"+$(this)[0].location.lng+"'>"+$(this)[0].name+"<div class='dizhi'>"+$(this)[0].address+"</div></div>");
                if(!lacationhash[$(this)[0].id]){
                    lacationhash[$(this)[0].id]={"name":$(this)[0].name,"address":$(this)[0].address,"location":$(this)[0].location}
                }
            });
        });
    });
}
    //高德地图//调用地图
function startmap(){
    //高德地图
    var map, geolocation;
//加载地图，调用浏览器定位服务
    map = new AMap.Map('mapplace', {resizeEnable: true});
    map.plugin('AMap.Geolocation', function() {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            noIpLocate:0,
            GeoLocationFirst:false,//默认为false，设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位
            convert: true,         //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            timeout: 100000,          //超过100秒后停止定位，默认：无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            buttonPosition:'RB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
    });
//解析定位结果
    function onComplete(data) {
        var shiname=data.formattedAddress.split("省")[1].split("市")[0]+"市";
        shengshi=shiname;
        nowlocation=data.position;
        $("#shiname div").html(shiname);
        otherlocal(data.position,shiname,pageindex);
    }
//解析定位错误信息
    function onError(data) {
        //document.getElementById('tip').innerHTML = '定位失败';
    }
}
startmap();
//发高额经验
function sendh(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName){
    if(parseFloat($("#unitprice").val())<1){
        $("#errorword span").css("display","block");
        $("#errorword span").html("金额不能低于1元");
    }else if(parseFloat($("#unitprice").val())>999){
        $("#errorword span").css("display","block");
        $("#errorword span").html("金额不能超过999元");
    }else{
        if(!/^\d+$/g.test($("#allday").val())){ //------------------
            $("#errorword span").css("display","block");
            $("#errorword span").html("天数不能为空");
        }else{
            if(parseFloat($("#allday").val())>365){
                $("#errorword span").css("display","block");
                $("#errorword span").html("天数不能超过365天");
            }else if(parseFloat($("#allday").val())<1){
                $("#errorword span").css("display","block");
                $("#errorword span").html("天数必须在1-365之间");
            }else{
                if(!/^\d+$/g.test($("#allprice").val())){
                    $("#errorword span").css("display","block");
                    $("#errorword span").html("预期总收益不能为空");
                }else if(parseFloat($("#allprice").val())>9999){
                    $("#errorword span").css("display","block");
                    $("#errorword span").html("总收入不能超过9999元");
                }
                else{
                    if(parseFloat($("#allprice").val())<parseFloat($("#unitprice").val())){ //------------------
                        $("#errorword span").css("display","block");
                        $("#errorword span").html("总收入不能小于单价");
                    }else{
                        //经验的金额
                        if(document.getElementById("unitprice").value&&qtypenum==3){
                            if(document.getElementById("unitprice").value.match(/^[0-9]+$/g)){
                                question.score=parseFloat(document.getElementById("unitprice").value)*100;//分数
                                question.unitamount=parseFloat(document.getElementById("unitprice").value)*100;//分数
                                question.isexphigh=1;
                                question.totalamount=parseFloat(document.getElementById("allprice").value)*100;//总额
                                question.expireDay=parseFloat(document.getElementById("allday").value);//期限
                                //可以提交数据
                                sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName);
                            }
                        }
                    }
                }
            }
        }
    }
}
//发普通经验
function sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName){
    //单身资源好友类型
    //var onlypersons=persons;
    //if(/goSingle/.test(location.href)){
    //    if(isSingleCallSee){
    //        onlypersons="";
    //    }else if(isSingleOnlySee){
    //        person="";
    //    }else{
    //        onlypersons="";person="";
    //    }
    //}
    //删除重复召唤问题
    //if(singleCallPerson&&singleCallPerson.length>0&&persons&&persons.length>0){
    //    if(persons.indexOf(singleCallPerson[0])>-1){
    //        var delIndex=persons.indexOf(singleCallPerson[0]);
    //        persons.splice(delIndex,1);
    //    }
    //}
    //花钱给上层看
    var personsRecomment=[];
    var allPayMoney=0;
    if(choicePuluPeople){
        var allChoiceInput=$(".puluPeopleList input"),len=allChoiceInput.length;
        for(var i=0;i<len;i++){
            if(allChoiceInput[i].checked){
                personsRecomment.push({
                    "userId":allChoiceInput[i].id,
                    "score":allChoiceInput[i].value
                });
                allPayMoney+=parseFloat(allChoiceInput[i].value)/100;
            }
        }
    };
    if(allPayMoney>userallmoney){
        alert("您的余额不足");
    }else{
        var senddata={"atmeuserId": $.cookie("MYID"), "pulu_question": question, "persons": persons, "imgs": imgs, "jobtypes": jobtypes, "hobbytypes": hobbytypes, "qSeePlist": sendcanseelist,"atmeIsHideName":atmeIsHideName,"qcanseepersons":persons,"pulu_redbag":pulu_redbag,"persons1":singleCallPerson,"personsRecomment":personsRecomment};
        var sendurl="https://www.pulu.com/webapi/api/puluquestion/AddPulu_question_e";
        if(question.qtype==2){
            senddata={"atmeuserId":$.cookie("MYID"), "pulu_question": question, "persons": persons, "imgs": imgs, "jobtypes": jobtypes, "hobbytypes": hobbytypes, "qSeePlist": sendcanseelist,"qcanseepersons":persons,"personsRecomment":personsRecomment};
            sendurl="https://www.pulu.com/webapi/api/puluquestion/AddPulu_question_q";
        }
        //问题转经验  //{"questionId":qid, "pulu_question": question,"imgs": imgs},
        if(/queChange/.test(location.href)){
            question.content=$("#contentword").val();
            qid=(location.href).match(/queChange=[0-9]+/)[0].match(/[0-9]+/)[0];
            senddata={"questionId":qid,"atmeuserId":$.cookie("MYID"), "pulu_question": question, "persons": persons, "imgs": imgs, "jobtypes": jobtypes, "hobbytypes": hobbytypes, "qSeePlist": sendcanseelist,"atmeIsHideName":atmeIsHideName,"qcanseepersons":persons};
            sendurl="https://www.pulu.com/webapi/api/PuluQuestion/ConvertToPulu_question_e";
        }
        if(
            question.qtype==2&&
            (parseFloat(document.getElementById("price").value)>userallmoney||
            parseFloat(document.getElementById("price").value)+allPayMoney>userallmoney)
        ){
            alert("您的余额不足，请重新设置问题的悬赏金额");
            $("#price").val("");
        }else{
            //上传提示提示框
            $("#sendinfo").css("display","block");
            $(".paynoteplace").css("display","none");
            $("body").attr("class","").css("height","auto");
            $.ajax({
                //提交数据的类型 POST GET
                type: "post",
                //提交的网址
                url: sendurl,
                //提交的数据
                data:senddata,
                //返回数据的格式
                datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                //成功返回之后调用的函数
                success: function (data) {
                    if(data.Code=="TRUE"){
                        location.href="http://www.pulu.com/weixin/pulu.html";
                    }else{
                        $("#sendinfo").css("display","none");
                        alert("关键词未在文中出现，请修改关键词");
                    };
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    location.href="http://www.pulu.com/weixin/pulu.html";
                }
            });
        }
    }

}
//获取页面参数
function getExpData(){
    //普通高额共用参数
    //图片
    if($(".mainshowimgbox")[0]){
        //从数组中获取图片
        imgs=[];
        //问题转经验
        if(/queChange/.test(location.href)){
            for(var key in imghash){
                if(imghash[key]){
                    var img={};
                    img.name=imghash[key];
                    imgs.push(img);
                }
            }
        }
        //正常发布
        else{
            for(var key in imghash){
                if(imghash[key]){
                    var img={};
                    img.plist ="";
                    img.name=imghash[key];
                    imgs.push(img);
                }
            }
        }
    }
    else{
        //单身资源 要有图片
        if(question.qtype==4){
            alert("至少上传一张照片");
            return;
        }
    }
    question.content = document.getElementById("contentword").value;
    question.questionUserId = id;//发布人的id
    question.status ="1";
    if($(".myctywords span")){question.pululocation = $(".myctywords").html();}
    var hobbytypes = [];//兴趣
    var jobtypes = [];//行业
    var sendcanseelist = [];//可见人的id列表

    //if(question.iswhocansee ===1){
    //    var seelabellistimg=document.querySelectorAll("#someseelabel .labelbox .labellist .labelbtnimg");
    //    for(var ii=0;ii<seelabellistimg.length;ii++){
    //        if(seelabellistimg[ii].src.match("hook01")){
    //            var num=seelabellistimg[ii].dataset.i;
    //            for(var iii=0;iii<labeldata[num].userList.length;iii++ ){
    //                sendcanseelist.push(labeldata[num].userList[iii].userId);
    //            }
    //        }
    //    }
    //}
    //else if(question.isforbidwhosee ===1){
    //    var notlabellistimg=document.querySelectorAll("#cannotseelabel .labelbox .labellist .labelbtnimg");
    //    for(var rr=0;rr<notlabellistimg.length;rr++){
    //        if(notlabellistimg[rr].src.match("hook01")){
    //            var num1=notlabellistimg[rr].dataset.i;
    //            for(var rrr=0;rrr<labeldata[num1].userList.length;rrr++ ){
    //                sendcanseelist.push(labeldata[num1].userList[rrr].userId)
    //            }
    //        }
    //    }
    //}
    //else if(question.iswhocansee ===0&&question.isforbidwhosee ===0){
    //    sendcanseelist=[];
    //}

    //发送问题的关键字
    question.keywords=$("#keywordinput").val();
    //console.log(sendcanseelist);
    var callerid="";
    if(persons.length>0){
        callerid=id;
    }
    //判断输入数字是否符合要求
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
    var urlregex = new RegExp("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~])+");
    if(urlregex.test($("#urlword").val())){question.relateUrl=$("#urlword").val()};
    //发经验
    if(question.qtype!=2){
        //发高额经验
        if($("#hexpinput").prop("checked")){
            if(!/^\d+$/g.test($("#unitprice").val())) {
                $("#errorword span").css("display","block");
                //$("#errorword>ul").css("display","none");
                $("#errorword span").html("金额不能为空");
            }else {
                $("#sendinfop").html("正在发布，请耐心等待..");
                sendh(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName)
            }
        }
        //发普通
        if($("#norexpinput").prop("checked")){
            question.score=30;//分数
            if(question.qtype!=2&&question.qtype!=3){
                if($("#new4moneyFree").prop("checked")){question.score=0}else{
                    if($("#new4redPay").prop("checked")){//红包
                        question.score=0;
                    }else{
                        question.score=parseFloat(document.getElementById("new4moneyinput").value)*100;
                    }
                }
            }
            $("#sendinfop").html("正在发布，请耐心等待..");
            //$("#sendinfop").html("正在发布经验，请耐心等待系统智能审核..");
            //问题转经验
            if(/queChange/.test(location.href)){
                question.qtype="";
                question.isexphigh=0;
                question.unitamount=30;
                question.totalamount=0;
                question.expireDay=0;
            }
            sendn(callerid,question,persons,imgs,jobtypes,hobbytypes,sendcanseelist,atmeIsHideName)
        }
    }
    //发问题
    else{
        isSendQue();
    }
}
//发问题
//$("#sendquebtn").click(function(){
function isSendQue() {
    //图片
    if (document.getElementsByClassName("mainshowimgbox")[0]) {
        imgs = [];
        //从数组中获取图片
        var imgbox = document.getElementsByClassName("mainshowimgbox");
        for (var i = 0, len = imgbox.length; i < len; i++) {
            var img = {};
            img.plist = "";
            if (!/Images\//.test(imgbox[i].dataset.img)) {img.name = "Images/" + imgbox[i].dataset.img + ".jpg";}
            else {img.name = imgbox[i].dataset.img;}
            imgs.push(img);
        }
    } else {imgs = "[]";}
    question.content = document.getElementById("contentword").value;
    question.questionUserId = id;//发布人的id
    question.status = "1";
    if ($(".myctywords span")) {question.pululocation = $(".myctywords").html();}
    //兴趣
    var hobbytypes = [];
    //行业
    var jobtypes = [];
    //可见人的id列表
    var sendcanseelist = [];
    //if (question.iswhocansee === 1) {
    //    var seelabellistimg = document.querySelectorAll("#someseelabel .labelbox .labellist .labelbtnimg");
    //    for (var ii = 0; ii < seelabellistimg.length; ii++) {
    //        if (seelabellistimg[ii].src.match("hook01")) {
    //            var num = seelabellistimg[ii].dataset.i;
    //            for (var iii = 0; iii < labeldata[num].userList.length; iii++) {
    //                sendcanseelist.push(labeldata[num].userList[iii].userId);
    //            }
    //        }
    //    }
    //}
    //else if (question.isforbidwhosee === 1) {
    //    var notlabellistimg = document.querySelectorAll("#cannotseelabel .labelbox .labellist .labelbtnimg");
    //    for (var rr = 0; rr < notlabellistimg.length; rr++) {
    //        if (notlabellistimg[rr].src.match("hook01")) {
    //            var num1 = notlabellistimg[rr].dataset.i;
    //            for (var rrr = 0; rrr < labeldata[num1].userList.length; rrr++) {
    //                sendcanseelist.push(labeldata[num1].userList[rrr].userId)
    //            }
    //        }
    //    }
    //}
    //else if (question.iswhocansee === 0 && question.isforbidwhosee === 0) {
    //    sendcanseelist = [];
    //}
    //发送问题的关键字
    question.keywords = $("#keywordinput").val();
    var callerid = "";
    if (persons.length > 0) {callerid = id;}
    //判断输入数字是否符合要求
    $("#errorword span").css("display", "none");
    $("#errorword>ul").css("display", "block");
    //普通经验 问题共用方法
    if (!document.getElementById("price").value) {alert("问题金额不能低于1元");}
    else {
        question.score = parseFloat(document.getElementById("price").value) * 100;//分数
        $("#sendinfop").html("正在发布，请耐心等待..");
        sendn(callerid, question, persons, imgs, jobtypes, hobbytypes, sendcanseelist, atmeIsHideName)
    }
}
//});


/*
 监听按钮及输入
*/
    //监听输入框数字（纯一位数字）
$("#unitprice").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#unitprice").val())){
        $("#unitprice").val($("#unitprice").val().replace(/[^0-9]/ig,""));
        if($("#unitprice").val().length>3){
            $("#unitprice").val(($("#unitprice").val()).substr(0,3));
        }
    }
    if($("#unitprice").val()){
        $("#unitprice").val(parseFloat($("#unitprice").val()));
        if($("#unitprice").val().length>3){
            $("#unitprice").val(($("#unitprice").val()).substr(0,3));
        }
    }
});

$("#allday").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#allday").val())){
        $("#allday").val($("#allday").val().replace(/[^0-9]/ig,""));
        if($("#allday").val().length>3){
            $("#allday").val(($("#allday").val()).substr(0,3));
        }
    }
    if($("#allday").val()){
        $("#allday").val(parseFloat($("#allday").val()));
        if($("#allday").val().length>3){
            $("#allday").val(($("#allday").val()).substr(0,3));
        }
    }
});

$("#allprice").bind('input propertychange',function(){
    //包含其他字符
    if(!/^[0-9]+$/.test($("#allprice").val())){
        $("#allprice").val($("#allprice").val().replace(/[^0-9]/ig,""));
        if($("#allprice").val().length>4){
            $("#allprice").val(($("#allprice").val()).substr(0,4));
        }
    }
    if($("#allprice").val()){
        $("#allprice").val(parseFloat($("#allprice").val()));
        if($("#allprice").val().length>4){
            $("#allprice").val(($("#allprice").val()).substr(0,4));
        }
    }
});
    //监听输入框数字变化取消提醒文字
$("#unitprice").on("input propertychange",function(){
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
});

$("#allprice").on("input propertychange",function(){
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
});

$("#allday").on("input propertychange",function(){
    $("#errorword span").css("display","none");
    $("#errorword>ul").css("display","block");
});

$("#price").on('input propertychange',function(){
    if(!/^[0-9]+$/.test($("#price").val())||$("#price").val()==0){
        $("#price").val("");
    }else if($("#price").val()>9999){$("#price").val(9999);}
    //changeBodyHeight();
});

$(".td input").on("change",function(e){
    //console.log(e.target.id);
    if($(e.target).prop("checked")){
        if(chickednum>=3){
            $(e.target).attr("checked",false);
        }
        else{
            chickednum++;
            switch(e.target.id) {
                case "chikui":question.chikui=1;break;
                case "huasuan":question.huasuan=1;break;
                case "xinqi":question.xinqi=1;break;
                case "qita":question.qita=1;break;
                case "tuijiandy":question.tuijiandy=1;break;
                case "tuijianfd":question.tuijianfd=1;break;
                case "youwan":question.youwan=1;break;
                case "shu":question.shu=1;break;
                case "nearlyexp":
                    question.fujinjy=1;
                    $("#locationbox").css("display","block");
                    break;
                case "rensheng":question.rensty=1;break;
                case "yejy":question.yejy=1;break;
                case "gzjy":question.gzjy=1;break;
                case "gwjy":question.gwjy=1;break;
                case "jkjy":question.jkjy=1;break;
            }
        }
    }
    else{
        chickednum--;
        switch(e.target.id) {
            case "chikui":question.chikui=0;break;
            case "huasuan":question.huasuan=0;break;
            case "xinqi":question.xinqi=0;break;
            case "qita":question.qita=0;break;
            case "tuijiandy":question.tuijiandy=0;break;
            case "tuijianfd":question.tuijianfd=0;break;
            case "youwan":question.youwan=0;break;
            case "shu":question.shu=0;break;
            case "nearlyexp":
                question.fujinjy=0;
                $("#locationbox").css("display","none");
                question.longitude="";
                question.latitude="";
                //同不选择城市
                $("#location div:nth-child(2)").html("所在位置");
                $("#location2 div:nth-child(2)").html("所在位置");
                $(".myctywords").css("display","none");
                $(".myctywords").html("");
                $("#firstchoice").css("display","none");
                $("#showmap").css("display","none");//页面
                $("#nolocation img").css("display","block");
                $("#firstchoice img").css("display","none");
                $("#shiname img").css("display","none");
                break;
            case "rensheng":question.rensty=0;break;
            case "yejy":question.yejy=0;break;
            case "gzjy":question.gzjy=0;break;
            case "gwjy":question.gwjy=0;break;
            case "jkjy":question.jkjy=0;break;
        }
    }
});
//绑定输入
$('#locationsearch input').bind('input propertychange', function() {
    //城市搜索
    $("#searclocation div").remove();
    searchcity(pagenum);
});

$(window).scroll(function(){
    if($("#showmap").css("display")==="block"){
        var mainheight=$("#showmap").height();
        var windowheight=$(window).height();
        var chajuli=$("#showmap").offset().top - $(window).scrollTop();
        var cz=windowheight-mainheight+5;
        if(chajuli<cz){
            if($("#searclocation").css("display")==="none"){
                pageindex++;
                otherlocal(nowlocation,shengshi,pageindex);
            }
            else{
                pagenum++;
                searchcity(pagenum);
            }
        }
    }
});


/*
  键盘回车
*/
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){
        //城市搜索
        $("#searclocation div").remove();
        searchcity(pagenum);
        //好友搜索
        //if(imgchoicefriend.style.display==="block"){
        //    var word=$("#csearchinput1").val();
        //    $("#aa").css("display","none");
        //    $("#a1 div").remove();
        //    if(friendarr&&friendarr.length>0&&$("#csearchinput1").val()){
        //        var word=$("#csearchinput1").val();
        //        for(var i=0;i<friendarr.length;i++){
        //            var friendnick="";
        //            friendnick=friendarr[i].friendnick;
        //            //如果好友列表中有搜索内容
        //            if(friendnick.match(word)){
        //                //如果是标签组搜索
        //                if(isaddnewlabel===0){
        //                    var num=0;
        //                    var dis="";
        //                    for(var x=0;x<labeldata[lid].userList.length;x++){
        //                        num++;
        //                        if(friendnick===labeldata[lid].userList[x].nick){dis="disabled='disabled' checked='checked'";}
        //                    }
        //                    if(num===labeldata[lid].userList.length){
        //                        $("#a1").append("<div class='section_header section_header_gray' data-num='"+i+"' style='display:none'> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' "+dis+" data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'><img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/> </a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
        //                    }
        //                    // 如果是新建搜索
        //                }else if(isaddnewlabel===1){
        //                    $("#a1").append("<div class='section_header section_header_gray' data-num='"+i+"' style='display:none'> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox' class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'><img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/> </a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
        //                }
        //            }
        //        }
        //        $("#a1").css("display","block");
        //    }
        //}
    }
};

    //红包金额
//$("#new4redinput").bind("input","change",function(){
//    $("#new4moneyFree").prop("checked",false);
//    $("#new4redPay").prop("checked",true);
//    $("#new4moneyPay").prop("checked",false);
//    if($("#new4redinput").val().match(/^[1-9]$|^[1-9][0-9]{1,2}$|^[1-9][0-9]{1,2}\.[0-9]{1}$|^[1-9]{1,3}\.[0-9]{1}$|^0\.[1-9]$/)){
//        if(parseFloat($("#new4redinput").val())>100){$("#new4redinput").val(100);}
//    }else{
//        if(parseFloat($("#new4redinput").val())>100){$("#new4redinput").val(100);}
//        if(/^0[0-9]+/.test($("#new4redinput").val())){$("#new4redinput").val($("#new4redinput").val().replace(/^0/,""));}
//        if(/\./.test($("#new4redinput").val())){
//            $("#new4redinput").val($("#new4redinput").val().match(/[0-9]{1,4}\.[0-9]{1}/)[0]);
//            if($("#new4redinput").val()=="0.0"){$("#new4redinput").val(0.1)}
//        }
//        if(/^00/.test($("#new4redinput").val())){$("#new4redinput").val(0.1)}
//    }
//});
//红包个数
//$("#new4redNum").bind("input","change",function(){
//    $("#new4moneyFree").prop("checked",false);
//    $("#new4redPay").prop("checked",true);
//    $("#new4moneyPay").prop("checked",false);
//    if(!/^[0-9]+$/.test($("#new4redNum").val())){$("#new4redNum").val();}
//    if(parseFloat($("#new4redNum").val())>=100){$("#new4redNum").val(100);}
//    if(/^0+$/.test($("#new4redNum").val())){$("#new4redNum").val(1);}
//    if(parseFloat($("#new4redNum").val())>=100){$("#new4redNum").val(100);}
//});
////选择资源金额类型 展示输入区 单选框
//$("#new4moneyFree").click(function(){
//    $("#new4moneyinput").val("");
//    $("#new4redNum").val("");
//    $("#new4redinput").val("");
//    $("#new4money1").css("display","block");
//    $("#new4money2").css("display","none");
//    $("#new4money3").css("display","none");
//});
//$("#new4moneyPay").click(function(){
//    $("#new4redNum").val("");
//    $("#new4redinput").val("");
//    $("#new4money1").css("display","none");
//    $("#new4money2").css("display","block");
//    $("#new4money3").css("display","none");
//});
//$("#new4redPay").click(function(){
//    $("#new4moneyinput").val("");
//    $("#new4money1").css("display","none");
//    $("#new4money2").css("display","none");
//    $("#new4money3").css("display","block");
//});



//右侧导航条点击跳转 好友列表
//字母键
//var englishbtn1=document.querySelectorAll(".rightnav1 div.zmbtn");//导航条跳转
//
//for(var en1=0;en1<englishbtn1.length;en1++){
//    englishbtn1[en1].onclick=function(e){
//        if($(".section_header.section_header_gray."+(e.target.innerHTML).toLowerCase()).length>0){
//            var engtitlenum=parseFloat(hasharr[e.target.innerHTML]);
//            var divnum=parseFloat(document.querySelector(".section_header.section_header_gray."+(e.target.innerHTML).toLowerCase()).dataset.num);
//            var divheight=$(".friends").eq(0).height();
//            var titleheight=$("div.section_header.section_header_gray").eq(0).height();
//            heightdiv=titleheight*engtitlenum+divnum*divheight;
//            $(window).scrollTop(0);
//            $(window).scrollTop(heightdiv);
//
//        }
//    };
//}





//匿名发布
//hidename.onclick=function(){
//    if(question.ishidename ===0){
//        question.ishidename = 1;
//        atmeIsHideName=1;
//        $("#hidename div.changephotobox img").attr("src","img/hook01.png")
//    }else if(question.ishidename ===1){
//        question.ishidename =0;
//        atmeIsHideName=0;
//        $("#hidename div.changephotobox img").attr("src","img/hook-no.png")
//    }
//};

//陌生人不可见（问题经验）
//strangecansee.onclick=function(){
//    if(question.isstrangersee ===1){
//        question.isstrangersee =0;
//        $("#strangecansee div.changephotobox img").attr("src","img/hook01.png")
//    }else if(question.isstrangersee ===0){
//        question.isstrangersee =1;
//        $("#strangecansee div.changephotobox img").attr("src","img/hook-no.png")
//    }
//};

//改变页面高度距离隐藏显示
//function changeBodyHeight(){
//    if(window.getComputedStyle){
//        var screenHeight=window.getComputedStyle(document.getElementsByClassName("paynoteplace")[0])["height"];
//    }else{
//        var screenHeight=document.getElementsByClassName("paynoteplace")[0].currentStyle["height"];
//    };
//    $("body").css("height",screenHeight);
//}

//$("#price").focus(function(){
//    setTimeout(function(){
//        changeBodyHeight();
//        clearTimeout();
//    },1000);
//});
//$("#price").blur(function(){
//    changeBodyHeight();
//});
//function singleToggleType(){
//    if($("#singleCall").prop("checked")){ //单身提醒谁看
//        isSingleCallSee=true;
//        isSingleOnlySee=false;
//        $("#callfriendwords2").css("display","block");//单身资源选择好友按钮
//    }else if($("#singleOnly").prop("checked")){//单身只给谁看
//        isSingleCallSee=false;
//        isSingleOnlySee=true;
//        $("#callfriendwords2").css("display","block");//单身资源选择好友按钮
//    }else{//不选
//        $("#callfriendwords2").css("display","none");//单身资源选择好友按钮
//        isSingleCallSee=false;
//        isSingleOnlySee=false;
//    }
//}
//单身提醒谁看切换
//$("#singleCall").click(function(){
//    $("#singleOnly").prop("checked",false);
//    singleToggleType()
//});
//单身只给谁看切换
//$("#singleOnly").click(function(){
//    $("#singleCall").prop("checked",false);
//    singleToggleType()
//});
//问题经验提醒谁看@ 只给谁看
//callfriend.onclick=function(){
//    ////单身资源单独做处理
//    //if(/goSingle/.test(location.href)){
//    //
//    //}
//    isSingleCallSee=false;
//    isSingleOnlySee=true;
//    //控制选择框状态
//    $("#maina input").prop("checked",false);
//    if(persons.length>0){
//        //console.log("you");
//        $(persons).each(function(i,e){
//            //console.log(e);
//            $(".friends#"+e+" input").prop("checked",true);
//        })
//    }
//    bodyplace.style.display="none";
//    imgchoicefriend.style.display="block";//与图片共用一个好友列表
//    $(window).scrollTop(0);
//    sendfriend=1;
//    callfrienfname=[];
//};
//单身资源选择好友
//callfriend2.onclick=function(){
//    isSingleCallSee=true;
//    isSingleOnlySee=false;
//    //控制选择框状态
//    $("#maina input").prop("checked",false);
//    if(singleCallPerson.length>0){
//        $(singleCallPerson).each(function(i,e){
//            $(".friends#"+e+" input").prop("checked",true);
//        })
//    }
//    bodyplace.style.display="none";
//    imgchoicefriend.style.display="block";//与图片共用一个好友列表
//    $(window).scrollTop(0);
//    sendfriend=1;
//    callfrienfname=[];
//};
//提醒谁看 只给谁看
//imgchoicedFDokbtn.onclick=function(){
//    imgchoicefriend.style.display="none";
//    bodyplace.style.display="block";
//    if(!isSingleCallSee){
//        var choicefriendlist=$("#sd-imgchoicefriend .addchatpeoplebtn");//所有好友列表 单选按钮
//        persons = [];
//        for(var f=0;f<choicefriendlist.length;f++){
//            if(choicefriendlist[f].checked==true){
//                persons.push(choicefriendlist[f].parentNode.id);
//                var childlist=choicefriendlist[f].parentNode.childNodes;
//                for(var i=0;i<childlist.length;i++){
//                    if(childlist[i].className==="innerplace tc_text"){ //wentibufen
//                        callfrienfname.push(childlist[i].innerHTML);
//                    }
//                }
//            }
//        }
//        if($("#callfriendwords span")){$("#callfriendwords span").remove();}
//        if(callfrienfname.length!=0){
//            if(callfrienfname.length>3){
//                $("#callfriendwords").append("<span>"+callfrienfname[0]+","+callfrienfname[1]+","+callfrienfname[2]+"等"+callfrienfname.length+"人"+"</span>")
//            }else{
//                for(var ii=0;ii<callfrienfname.length;ii++){$("#callfriendwords").append("<span>"+callfrienfname[ii]+"</span>")}
//            }
//        }else{
//            $("#choiceFriendWord").css("display","block");
//            $("#callfriendwords2 span:not('#choiceFriendWord')").remove();
//        }
//    }
//};
//监听选择框 单身只能选一个
//$("#maina").bind("click","input",function(i){
//    //console.log("执行");
//    if($(i.target).prop("type")=="checkbox"){
//        if(isSingleCallSee&&$(i.target).prop("checked")){
//            singleCallPerson=[$(i.target).parent(".friends").attr("id")];
//            //console.log(singleCallPerson);
//            imgchoicefriend.style.display="none";
//            bodyplace.style.display="block";
//            $("#callfriendwords2").html("<span>"+$(i.target).parent(".friends").children(".tc_text").html()+"</span>")
//        }else if(isSingleCallSee&&!$(i.target).prop("checked")){
//            //console.log("清除");
//            singleCallPerson=[];
//            $("#callfriendwords2").html("");
//        }
//    }
//});
//提醒谁看页面关闭
//$("#friendlistgoback").click(function(){
//    $("#sd-imgchoicefriend").css("display","none");
//    $("#page_wrapper").css("display","block");
//});

//$("#gaojibtn").click(function(){
//    if($("#gaojilistbox").css("display")=="block"){
//        $("#gaojilistbox").css("display","none");
//        $("#gaojiimg").attr("src","img/darr01.png");
//    }else{
//        $("#gaojilistbox").css("display","block");
//        $("#gaojiimg").attr("src","img/uarr01.png");
//    }
//});